from django.db import models

# Create your models here.

class University(models.Model):
    name = models.CharField(max_length=254, null=False, default='')
    class Meta:
        db_table = 'university_tb'

class Colleage(models.Model):
    name = models.CharField(max_length=254, null=False, default='')
    university = models.ForeignKey('University')
    class Meta:
        db_table = 'colleage_tb'

class Teacher(models.Model):
    name = models.CharField(max_length = 50)
    age = models.IntegerField()
    intime = models.DateTimeField()
    colleage = models.ForeignKey('Colleage')
    class Meta:
        db_table = 'teacher_tb'
    def __unicode__(self):
        return self.name
       
class Course(models.Model):
    name = models.CharField('Course Name', max_length=254, null=False, default='')
    teacher = models.ForeignKey('Teacher', )
    class Meta:
        db_table = 'course_tb'


class InterestingGroup(models.Model):
    name = models.CharField(max_length = 50)
    members = models.ManyToManyField('Student', through = 'MemberShip')
    class Meta:
        db_table = 'interesting_group'
    def __unicode__(self):
        return self.name
        
class Student(models.Model):
    name = models.CharField(max_length = 50)
    age = models.IntegerField()
    intime = models.DateTimeField()
    teacher = models.ForeignKey(Teacher, related_name = 'student_teacher')
    class Meta:
        db_table = 'student'
    def __unicode__(self):
        return self.name

class MemberShip(models.Model):
    group = models.ForeignKey('InterestingGroup')
    student = models.ForeignKey('Student')
    class Meta:
        db_table = 'member_ship'
    

